<?php
namespace Framework\Library\Utility;

/**
 * 模型标识检索器
 */
class IdentitySearcher{
	
	public $entity = NULL;
	public $pagingParameter = NULL;
	public $condition = NULL;
	
	function __construct( $entity,  $paging_parameter, $condition = NULL ){
		
		$this->entity = $entity;
		$this->pagingParameter = $paging_parameter;
		$this->condition = $condition;
		
	}
	
	public function get(){
		
		$offset = ( $this ->pagingParameter ->pagePosition - 1 ) * $this ->pagingParameter ->pageSize;
		$page_size = $this ->pagingParameter ->pageSize;
		$order_field = $this ->pagingParameter ->orderField;
		$order_pattern = $this ->pagingParameter ->orderPattern;
		
		$result = $this->entity->getDb()->select($this->entity->dbTable(),$this->condition,"$order_field $order_pattern","$offset,$page_size",array('id'));
		
		$ids = array();
		
		foreach($result as $id_array){
			
			array_push( $ids, $id_array['id'] );
			
		}
		
		return $ids;
		
	}
	
	public function getRecordCount(){
		
		return $this->entity->getDb()->count($this->entity->dbTable(),$this->condition);
		
	}
	
}